package com.wrupple.muba.catalogs.client.module.services.logic.impl;

import java.util.List;

import com.wrupple.muba.catalogs.client.channels.ICatalogVegetateChannel;
import com.wrupple.muba.catalogs.domain.CatalogEntry;
import com.wrupple.muba.common.shared.StateTransition;
import com.wrupple.vegetate.domain.CatalogResponseContract;

public class AbstractCatalogService {

	protected String tokenizeCatalogId(String catalogid,
			ICatalogVegetateChannel service) {
		if (catalogid.contains("@")) {
			String[] tokens = catalogid.split("@");
			catalogid = tokens[0];
			String host = tokens[1];
			service.setHost(host);
		}
		return catalogid;
	}

	protected StateTransition<CatalogResponseContract> createChannelCallback(
			StateTransition<List<CatalogEntry>> singletonSelector,
			String catalogid, ICatalogVegetateChannel service) {
		CatalogVegetateChannelTransitionWrapper vegetateCallback = new CatalogVegetateChannelTransitionWrapper(
				singletonSelector, catalogid);

		catalogid = tokenizeCatalogId(catalogid, service);

		return vegetateCallback;
	}

}
